//
//  TrainVc.m
//  SpiritWalk
//
//  Created by shange1999 on 16/3/11.
//  Copyright © 2016年 王鑫. All rights reserved.
//

#import "TrainVc.h"
#import "Tool.h"
@interface TrainVc ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,retain)UITableView *tableviewSelf;
@property(nonatomic,retain)NSMutableArray *tableviewArr;

@end

@implementation TrainVc

-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    self =[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.tableviewArr =[NSMutableArray array];
    }
    return self;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.navigationController.navigationBar.translucent=NO;
     self.title=@"健身";
     [self createView];
    [self createData];
      [self scrollReflsh];
    
}
#pragma 创建视图
-(void)createView{
    
    self.tableviewSelf=[[UITableView alloc ]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-64-49) style:0];
    self.tableviewSelf.rowHeight=250;
    [self.view addSubview:self.tableviewSelf];
    self.tableviewSelf.separatorStyle = NO;
    self.tableviewSelf.delegate=self;
    self.tableviewSelf.dataSource=self;
    
    UINib *nib = [UINib nibWithNibName:NSStringFromClass([TrainTableViewCell class]) bundle:nil];    //找到nib文件
    [self.tableviewSelf registerNib:nib forCellReuseIdentifier:@"myTBVCell"];   //注册,在nib文件里面找到当前需要注册的cell
    
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (self.tableviewArr.count==0) {
        return 0;
    }else{
    return self.tableviewArr.count;
    }
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    TrainTableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:@"myTBVCell" forIndexPath:indexPath];
    cell.selectionStyle=NO;
    cell.receiveModel = self.tableviewArr[indexPath.row];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    TrainDetailVc *vc =[[TrainDetailVc alloc]init];
      TrainVcModel *model = self.tableviewArr[indexPath.row];
    vc.receiveId =model.passId;
    vc.receiveUserid = model.userId;
    vc.titleStr=model.subject_name;
    
    [self.navigationController pushViewController:vc animated:YES];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return HEIGHT/3;
}



#pragma 解析数据
-(void)createData{
    NSString *usrStr=@"http://so.jianshen.so/Realtech/Course/courseList";
    NSDictionary *dic = @{@"userId" : @"9607",@"page":@"1"};
[Tool POST:usrStr parameters:dic black:^(id data) {
    self.tableviewArr  =[TrainVcModel baseModelByArr:data[@"data"][@"list"]];
     [self.tableviewSelf reloadData];
  
}];
}

-(void)scrollReflsh{
    self.tableviewSelf.mj_header=[MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [self createData];
            [self.tableviewSelf.mj_header endRefreshing];

    }];
}













- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
